// throttle, N秒内最多执行一次, 或者说每个N秒执行一次
// function throttle(fn, delay) {
//     let timer = null;

//     return function () {
//         let args = arguments;
//         if (!timer) {
//             timer = setTimeout(() => {
//                 clearTimeout(timer)
//                 fn(args)
//             }, delay);
//         }
//     }
// }


// 时间戳版的节流
function throttle(fn, delay) {
    let prevTime = 0;

    return function () {
        let args = arguments;
        let now = new Date().getTime();
        if (now - prevTime < delay) {
            return
        }
        prevTime = now;
        fn(args)
    }
} 